package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.bouncycastle.pqc.crypto.sphincs.SPHINCSPublicKeyParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/product")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService ;

    @GetMapping(value = "/baseTrademark/{page}/{limit}")
    public Result<Page<BaseTrademark>> findByPage(@PathVariable(value = "page") Integer pageNo , @PathVariable(value = "limit")Integer pageSize) {
        Page<BaseTrademark> page = baseTrademarkService.findByPage(pageNo , pageSize) ;
        return Result.build(page , ResultCodeEnum.SUCCESS) ;
    }

    @PostMapping(value = "/baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {      // @RequestBody从请求体中读取数据，然后将json数据封装到对应的实体对象中
        baseTrademarkService.save(baseTrademark) ;
        return Result.build(null , ResultCodeEnum.SUCCESS);
    }

    @GetMapping(value = "/baseTrademark/get/{id}")
    public Result<BaseTrademark> getById(@PathVariable(value = "id") Long id) {
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.build(baseTrademark , ResultCodeEnum.SUCCESS) ;
    }

    @PutMapping(value = "/baseTrademark/update")
    public Result updateById(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping(value = "/baseTrademark/remove/{id}")
    public Result deleteById(@PathVariable(value = "id") Long id) {
        baseTrademarkService.deleteById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/baseTrademark/getTrademarkList")
    public Result<List<BaseTrademark>> findAll() {
        List<BaseTrademark> baseTrademarkList = baseTrademarkService.list();
        return Result.build(baseTrademarkList , ResultCodeEnum.SUCCESS) ;
    }
}
